<?php
require_once('LapanganClass.php');
require_once('class.imageupload.php');  
$Lapangan = new Lapangan();

if(!isset($_POST['sewa']))
{
    header("../page/HOME_sewa.php");    
}
else {
	$image = new ImageUploader(5000000,'../img/lapangan/'); 
	$image->setImage('fupload');
	if(!$image->checkSize())
		$errors[] = "Ukuran foto melebihi 2MB";
	if(!$image->checkExt())
		$errors[] = "Type file salah";
		
	if(!isset($errors)){
		$image->setImageName('fupload');
		$image->deleteExisting();
		$image->upload();	
	}
	else{
		echo "<h2>upload error</h2><br>";
		print_r($errors);
	}
	
	$user = $_SESSION['username'];
    $nama_lap = $Lapangan->EscapeString($_POST['nama_lap']);
	$jadwal_lap = $Lapangan->EscapeString($_POST['jadwal_lap']);
    $kategori_lap =$Lapangan->EscapeString($_POST['Kategori']);
    $harga_lap = $Lapangan->EscapeString($_POST['harga_lap']);
	$keterangan_lap = $Lapangan->EscapeString($_POST['keterangan_lap']);
	$foto = $Lapangan->EscapeString($_FILES['fupload']['name']);

    $Lapangan->AddLapangan($user,$nama_lap,$jadwal_lap,$kategori_lap,$harga_lap,$keterangan_lap,$foto);
}

$Lapangan->Disconnect();
 
?>
